﻿Public Module MatchPatternExtensions
    <System.Runtime.CompilerServices.Extension()> _
    Public Function IsValid(ByVal pattern As Entities.MatchPattern) As Boolean
        If String.IsNullOrEmpty(pattern.Pattern) Then Return False

        Select Case pattern.Type
            Case Entities.MatchPatternType.RegEx
                Try
                    System.Text.RegularExpressions.Regex.IsMatch("kalle", pattern.Pattern)
                    Return True
                Catch ex As Exception
                    Return False
                End Try
            Case Entities.MatchPatternType.WildCard
                Try
                    Dim blnDummy As Boolean = "kalle" Like pattern.Pattern
                    Return True
                Catch ex As Exception
                    Return False
                End Try
            Case Else
                Return False
        End Select
    End Function

    <System.Runtime.CompilerServices.Extension()> _
    Public Function IsMatch(ByVal pattern As Entities.MatchPattern, ByVal input As String) As Boolean
        Select Case pattern.Type
            Case Entities.MatchPatternType.RegEx
                Return System.Text.RegularExpressions.Regex.IsMatch(input, pattern.Pattern)
            Case Entities.MatchPatternType.WildCard
                Return input Like pattern.Pattern
            Case Else
                Throw New NotImplementedException
        End Select
    End Function


End Module
